System Design Interview: An In-Depth Overview For System Designers (A Beginner's Guide) by Stuart Broad

System Design Interview: An In-Depth Overview For System Designers (A Beginner's Guide) by Stuart Broad

Author:Stuart Broad
Language: eng
Format: azw3
Published: 2017-08-22T07:00:00+00:00


Even though making these decisions up front is critical for the improved performance of the database application, you don’t have to adhere strictly to them. As you expand your caching usage, you should always keep these guidelines in the picture whether caching is necessary or not.

That said, let’s dive in to find out various caching design patterns that you can use for your Redis cluster applications.

Sharding

Sharding—a form of consistent hashing—is a design pattern where every key that’s part of the data-store forms what’s commonly known as the hash slot. I know you’re thinking, “What is a hash slot?”

Caching in Redis is implemented in nodes which can be in the form of hash tables. A hash table or the hash map is simply a data structure that implements an associative array in RAM which can help map keys to values. It uses a hashing function to perform this complex computation of mapping keys to values in the memory by computing an index into an array of hash slots.

Redis cluster has a total of 16384 hash slots. The computation of an index into an array of hash slots is done by taking the CRC16 (Cyclic Redundancy Check) of the key modulo 16384. Every node in the Redis Cluster handles a subset of the hash slots. For instance, if your cluster has 3 nodes, Node A can contain hash slots from 0 to 5500, and Node B can include hash slots from 5501 to 11000 while node C may have hash slots from 11001 to 164383.

The sharding approach is simple to understand and implement in any database application. Besides, using the hashing function makes it deterministic since the same cache key can be used to map to the same cache node.

However, the sharding approach may present some flaws to your data-driven application. This is because of the way the modulo function works. When the number of cache nodes increases, most of the hash keys will be re-mapped to new nodes. Some of the new nodes may have empty caches when the hashing function is used.

Client Libraries



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.